.TH std::proj(std::complex) 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::proj(std::complex) \- std::proj(std::complex)

.SH Synopsis
   Defined in header <complex>
   template< class T >                                  \fB(1)\fP \fI(since C++11)\fP
   std::complex<T> proj( const std::complex<T>& z );
   Additional overloads \fI(since C++11)\fP
   Defined in header <complex>
   std::complex<float>       proj( float f );

   std::complex<double>      proj( double f );                            (until C++23)

   std::complex<long double> proj( long double f );     (A)
   template< class FloatingPoint >                                        (since C++23)
   std::complex<FloatingPoint> proj( FloatingPoint f );
   template< class Integer >                                (B)
   std::complex<double> proj( Integer i );

   1) Returns the projection of the complex number z onto the Riemann sphere.
   For most z, std::proj(z) == z, but all complex infinities, even the numbers where
   one component is infinite and the other is NaN, become positive real infinity,
   (INFINITY, 0.0) or (INFINITY, -0.0). The sign of the imaginary (zero) component is
   the sign of std::imag(z).
   A,B) Additional overloads are provided for all integer and floating-point types,
   which are treated as complex numbers with positive zero imaginary component.

.SH Parameters

   z - complex value
   f - floating-point value
   i - integer value

.SH Return value

   1) The projection of z onto the Riemann sphere.
   A) The projection of std::complex(f) onto the Riemann sphere.
   B) The projection of std::complex<double>(i) onto the Riemann sphere.

.SH Notes

   The proj function helps model the Riemann sphere by mapping all infinities to one
   (give or take the sign of the imaginary zero), and should be used just before any
   operation, especially comparisons, that might give spurious results for any of the
   other infinities.

   The additional overloads are not required to be provided exactly as (A,B). They only
   need to be sufficient to ensure that for their argument num:

     * If num has a
       standard
       (until C++23) floating-point type T, then std::proj(num) has the same effect as
       std::proj(std::complex<T>(num)).
     * Otherwise, if num has an integer type, then std::proj(num) has the same effect
       as std::proj(std::complex<double>(num)).

.SH Example


// Run this code

 #include <complex>
 #include <iostream>

 int main()
 {
     std::complex<double> c1(1, 2);
     std::cout << "proj" << c1 << " = " << std::proj(c1) << '\\n';

     std::complex<double> c2(INFINITY, -1);
     std::cout << "proj" << c2 << " = " << std::proj(c2) << '\\n';

     std::complex<double> c3(0, -INFINITY);
     std::cout << "proj" << c3 << " = " << std::proj(c3) << '\\n';
 }

.SH Output:

 proj(1,2) = (1,2)
 proj(inf,-1) = (inf,-0)
 proj(0,-inf) = (inf,-0)

.SH See also

   abs(std::complex) returns the magnitude of a complex number
                     \fI(function template)\fP
   norm              returns the squared magnitude
                     \fI(function template)\fP
   polar             constructs a complex number from magnitude and phase angle
                     \fI(function template)\fP
   C documentation for
   cproj
